﻿using NPOI.POIFS.NIO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.BaseInfo;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Forum;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.BranchHome
{
    public partial class BranchLeaderWindow : UseMorePageMasterPage
    {
        /// <summary>
        /// BranchID
        /// </summary>
        private string BranchID
        {
            get
            {
                return this.Request["BranchID"] ?? "null";
            }
        }

        /// <summary>
        /// ID
        /// </summary>
        private string Id
        {
            get
            {
                return this.Request["ID"] ?? "null";
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            PartyOrgLeaderWindow polw = DB.PartyOrgLeaderWindows.Find(Id);
            if (polw != null)
            {
                this.image.Src = UpFileBusiness.GetFileUrl(polw.ImageUrl);
                this.txtWorkDistribution.Text = polw.WorkDistribution;
                this.txtIntroduction.Text = polw.Introduction;
                this.txtUserName.Text = polw.UserName;
                this.txtPost.Text = polw.Post;
            }
            else {
                IQueryable<PartyOrgLeaderWindow> q = DB.PartyOrgLeaderWindows.Where(a => a.BranchID == BranchID).Where(a => a.OrderNo == 1);
                if (q.Count() > 0)
                {
                    StringBuilder sbName = new StringBuilder();
                    StringBuilder sbImage = new StringBuilder();
                    StringBuilder sbPost = new StringBuilder();
                    StringBuilder sbWorkDistribution = new StringBuilder();
                    StringBuilder sbIntroduction = new StringBuilder();
                    foreach (PartyOrgLeaderWindow item in q)
                    {
                        sbName.Append(item.UserName + ",");
                        sbImage.Append(item.ImageUrl + ",");
                        sbPost.Append(item.Post + ",");
                        sbWorkDistribution.Append(item.WorkDistribution + ",");
                        sbIntroduction.Append(item.Introduction + ",");
                    }
                    this.image.Src = UpFileBusiness.GetFileUrl(sbImage.ToString().TrimEnd(','));
                    this.txtWorkDistribution.Text = sbWorkDistribution.ToString().TrimEnd(',');
                    this.txtIntroduction.Text = sbIntroduction.ToString().TrimEnd(',');
                    this.txtUserName.Text = sbName.ToString().TrimEnd(',');
                    this.txtPost.Text = sbPost.ToString().TrimEnd(',');
                }
            }
        }
    }
}